package com.example.glxt1.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.glxt1.common.Result;
import com.example.glxt1.entity.User;
import com.example.glxt1.mapper.UserMapper;
import com.example.glxt1.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fumeichuan
 * @since 2023-01-29
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

        @Resource
        private UserMapper userMapper;

       public Result userSave(User user){
            boolean flag=saveOrUpdate(user);
            if(flag){
                return Result.success();
            }else{
                return Result.error();
            }
        }

        public Result userDeleteBatch(List<String> ids){
            boolean flag=removeByIds(ids);
            if(flag){
                return Result.success();
            }else{
                return Result.error();
            }
        }

        public Result userDelete(String id){
            boolean flag=removeById(id);
            if(flag){
                return Result.success();
            }else{
                return Result.error();
            }
        }

        public Result userFindAll(){
            return Result.success(list());
        }

        public Result userFindOne(String id){
            return Result.success(getById(id));
        }

        public Result userFindPage(Integer pageNum,Integer pageSize){
        Page<User> pageList=page(new Page<>(pageNum, pageSize));
        return Result.success(pageList);
        }

}
